package com.hooper.threadpool.demo;

/**
 * 需求:
 * 自定义线程池练习,这是任务类;
 * 包含任务编号,每一个任务执行时间设计为0.2秒
 *
 * @author Tim Hooper
 * @version 1.0
 * @time 2023/03/02/18:03
 */
public class MyTask implements Runnable {
    private int id;

    public MyTask(int id) {
        this.id = id;
    }

    @Override
    public void run() {
        String threadName = Thread.currentThread().getName();
        System.out.println(threadName + " will run -- " + id);
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(threadName + " finished -- " + id);
    }

    @Override
    public String toString() {
        return String.valueOf(id);
    }
}
